from django.core.exceptions import ValidationError


def validate_port(value):
    value = int(value)
    if not 0 < value < 65536:
        raise ValidationError("%(value)s 不是端口号")


def validate_memory(value):
    value = int(value)
    if value < 4 or value > 128:
        raise ValidationError("%(value)s 在4~128G之间")
    if value % 2 != 0:
        raise ValidationError("%(value)s 是2的倍数")
